<?php

namespace app\api\controller;

use app\common\controller\Common;
use org\ChapterPage;
use org\Page;
use org\SiteMap;
use think\Db;
use think\facade\Cache;
use think\facade\Config;
use think\facade\Env;
use think\facade\Request;
use think\helper\Time;

class Home extends Common
{
    /**
     * 首页
     */
    public function index()
    {
        $channel = trim($this->request->param('channel', "winnow"));

        $cacheKey = md5("home_list_" . $channel);
        if (Cache::has($cacheKey)) {
            $data =  Cache::get($cacheKey);
        }else {
            $data = [
                'slide_list' => get_slide_list(),
                'block_list' => get_home_list($channel),
//            'update_list' => get_update_list($channel,1,20),
            ];
            Cache::set($cacheKey,$data,10);
        }

        return $this->echoJson($data);
    }

    /**
     * 分类
     */
    public function classify()
    {
        $config = get_app_config();
        return $this->echoJson($config['channel']);
    }

    /**
     * 分类小说列表
     */
    public function classify_list()
    {

        $type = trim($this->request->param('type', ""));
        $page = (int)trim($this->request->param('page', 1));
        $cid = (int)trim($this->request->param('cid', 0));
        $page_size = (int)trim($this->request->param('page_size', 20));

        $list = [];

        if ($type == "new_book") {
          $list = get_new_nook_list($page,$page_size);
        }else if ($type == "finish") {
            $list = get_finish_list($page,$page_size);
        }elseif ($type == "classify") {
            $list = get_classify_list($cid,$page,$page_size);
        }else {
            $list = get_update_list($type,$page,$page_size);
        }

        return $this->echoJson($list);
    }

    /**
     * 关于我们
     * @return mixed
     */
    public function about()
    {
        return $this->fetch();
    }


}
